package com.hayato.demo.client.Info;

import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.hayato.demo.client.model.OrderModel;
import com.hayato.demo.utils.PMF;

@PersistenceCapable
public class OrderInfo {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private Long customer_id;
	@Persistent
	private Date order_date;
	@Persistent
	private Date delivery_schedule_date;
	@Persistent
	private Date shop_schedule_date;
	@Persistent
	private Date delivery_finish_date;
	@Persistent
	private Date shop_finish_date;
	@Persistent
	private Double summary_money;
	@Persistent
	private String remark;
	@Persistent
	private Date date_created;
	@Persistent
	private Date date_updated;
	
	public OrderInfo() {
		Date today = new Date();
		
		order_date = today;
		date_created = today;
		date_updated = today;
	}
	
	public OrderInfo(OrderModel model){
		customer_id=model.getCustomer_Model().getId();
		order_date=model.getOrder_date();
		delivery_schedule_date=model.getDelivery_schedule_date();
		shop_schedule_date=model.getShop_schedule_date();
		delivery_finish_date=model.getDelivery_finish_date();
		shop_finish_date=model.getShop_finish_date();
		summary_money=model.getSummary_money();
		remark=model.getRemark();
	}
	
	public long getCustomer_id() {
		return customer_id;
	}

	public void setCustomer_id(long customer_id) {
		this.customer_id = customer_id;
	}

	public Date getOrder_date() {
		return order_date;
	}

	public void setOrder_date(Date order_date) {
		this.order_date = order_date;
	}

	public Date getDelivery_schedule_date() {
		return delivery_schedule_date;
	}

	public void setDelivery_schedule_date(Date delivery_schedule_date) {
		this.delivery_schedule_date = delivery_schedule_date;
	}

	public Date getShop_schedule_date() {
		return shop_schedule_date;
	}

	public void setShop_schedule_date(Date shop_schedule_date) {
		this.shop_schedule_date = shop_schedule_date;
	}

	public Date getDelivery_finish_date() {
		return delivery_finish_date;
	}

	public void setDelivery_finish_date(Date delivery_finish_date) {
		this.delivery_finish_date = delivery_finish_date;
	}

	public Date getShop_finish_date() {
		return shop_finish_date;
	}

	public void setShop_finish_date(Date shop_finish_date) {
		this.shop_finish_date = shop_finish_date;
	}

	public Double getSummary_money() {
		return summary_money;
	}

	public void setSummary_money(Double summary_money) {
		this.summary_money = summary_money;
	}

	public long getId() {
		return id;
	}

	public Date getDate_created() {
		return date_created;
	}

	public void setDate_created(Date date_created) {
		this.date_created = date_created;
	}

	public Date getDate_updated() {
		return date_updated;
	}

	public void setDate_updated(Date date_updated) {
		this.date_updated = date_updated;
	}
	
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public OrderModel toModel(){
		OrderModel model=new OrderModel();
		model.setId(getId());
		PersistenceManager pm = PMF.get().getPersistenceManager();
		CustomerInfo cusInfo;
		try {
			cusInfo = pm.getObjectById(CustomerInfo.class, customer_id);
		} catch (Exception e) {
			cusInfo = null;
		}
		model.setCustomer_Model(cusInfo.toModel());
		model.setOrder_date(getOrder_date());
		model.setDelivery_schedule_date(getDelivery_schedule_date());
		model.setShop_schedule_date(getShop_schedule_date());
		model.setDelivery_finish_date(getDelivery_finish_date());
		model.setShop_finish_date(getShop_finish_date());
		model.setSummary_money(getSummary_money());
		model.setRemark(getRemark());
		return model;
	}
	
}